package uno.rocc.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import uno.rocc.system.domain.dao.SysRole;
import uno.rocc.system.domain.dao.SysRolePermission;
import uno.rocc.system.mapper.SysRoleMapper;
import uno.rocc.system.service.SysRolePermissionService;
import uno.rocc.system.service.SysRoleService;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
    private final SysRolePermissionService sysRolePermissionService;


    /**
     * 角色添加权限
     *
     * @param id
     * @param permissionIds
     */
    @Override
    public void addPermission(Integer id, List<Integer> permissionIds) {
        List<SysRolePermission> list = permissionIds.stream().map(permissionId -> {
            SysRolePermission sysRolePermission = new SysRolePermission();
            sysRolePermission.setPermissionId(permissionId);
            sysRolePermission.setRoleId(id);
            return sysRolePermission;
        }).collect(Collectors.toList());
        sysRolePermissionService.saveBatch(list);
    }
}
